package gui.Reparation;

import gui.JTable_ColumnData;
import gui.JTable_StockData;
import gui.MainFrame;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;

import model.Reparation;

public class RJTable_StockTableData_old extends AbstractTableModel {
	static final public JTable_ColumnData m_columns[] = {
			new JTable_ColumnData("UniqueID", 60, JLabel.LEFT),
			new JTable_ColumnData("StartDate", 160, JLabel.LEFT),
			new JTable_ColumnData("EndDate", 160, JLabel.LEFT),
			new JTable_ColumnData("Machine", 60, JLabel.LEFT),
			new JTable_ColumnData("Duration", 100, JLabel.RIGHT) };
	protected List<JTable_StockData> m_list;
	protected Date m_date;

	public RJTable_StockTableData_old() {
		m_list = new ArrayList<JTable_StockData>();
	}

	/**
	 * TODO
	 * 
	 * @param reparation
	 */
	public void setDefaultData(List<Reparation> reparation) {
		m_list.clear();

		for (Reparation r : reparation) {
			String endDate = "";

			if (r.getEndDate() == null)
				endDate = "<Not Finished>";
			else
				endDate = MainFrame.getSimpleDateFormat().format(
						r.getEndDate().getTime());

			m_list.add(new JTable_StockData(r.getUniqueID(), MainFrame
					.getSimpleDateFormat().format(r.getStartDate().getTime()),
					endDate, r.getMachine().getName(), r.getDurationDetail()));
		}
	}

	public int getRowCount() {
		return m_list == null ? 0 : m_list.size();
	}

	public int getColumnCount() {
		return m_columns.length;
	}

	public String getColumnName(int column) {
		return m_columns[column].m_title;
	}

	public boolean isCellEditable(int nRow, int nCol) {
		return false;
	}

	public Object getValueAt(int nRow, int nCol) {
		if (nRow < 0 || nRow >= getRowCount())
			return "";
		JTable_StockData row = (JTable_StockData) m_list.get(nRow);
		switch (nCol) {
		case 0:
			return row.getR_uniqueID();
		case 1:
			return row.getR_startDate();
		case 2:
			return row.getR_endDate();
		case 3:
			return row.getR_machine();
		case 4:
			return row.getR_duration();
		}
		return "";
	}
}